import { ref, toRaw } from "vue"
import store from "@/store"
import { defineStore } from "pinia"
import { getAllPlaceApi } from "@/api/common/common.js"

export const useDict = defineStore("dict", () => {
  // 审核状态 债务人 担保人
  const auditStatus = ref([
    { label: "待审核", value: 0, color: '#FF732D' },
    { label: "审核通过", value: 1, color: '#00AD65' },
    { label: "审核拒绝", value: 2, color:'#F04040' },
    // { label: "待债务人审核", value: -1, color:'#FF732D' },
  ])
  // 查询审核状态label
  const getAuditStatusLabel = (id) => {
    let item = auditStatus.value.find( val => val.value === id)
    return item.label;
  }
  // 线索状态 线索有效无效：见字段“外网BC线索状态 0 有效 1 无效”
  const clueStatus = ref([
    // { label: "全部", value: '' },
    { label: "有效", value: 0 },
    { label: "无效", value: 1 }
  ])
  // 线索金额等级
  const amountLevel = ref([
    { label: "<50万", value: 1 },
    { label: "50~100万", value: 2 },
    { label: "100~500万", value: 3 },
    { label: "500~1000万", value: 4 },
    { label: ">=1000万", value: 5 }
  ])
  // 案件身份
  const caseIdentity = ref([
    { label: "原告", value: 1 },
    { label: "第三人", value: 2 }
  ])
  // 在职状态：查询
  const positionStatusQuery = ref([
    { label: "全部", value: undefined },
    { label: "在职", value: 0 },
    { label: "已离职", value: 1 }
  ])
  // 在职状态：编辑
  const positionStatus = ref([
    { label: "在职", value: 0 },
    { label: "已离职", value: 1 }
  ])
  // 案件类型
  const caseType = ref([
    { label: "民事案件", value: "civil" },
    { label: "刑事案件", value: "criminal" },
    { label: "行政案件", value: "administrative" },
    { label: "非诉保全案件", value: "implement" },
    { label: "执行案件", value: "preservation" },
    { label: "强制清算与破产案件", value: "bankrupt"}
  ])
  // 案件进展
  const caseProgress = ref([
    { label: "全部案件进展", value: "" },
    { label: "未结案", value: "0" },
    { label: "已结案", value: "1" }
  ])
  // 是否有文书详情
  const WsType = ref([
    {label: "全部",value: ""},
    {label: "有",value:"1"},
    {label: "无",value:"0"},
  ])
  // 诉讼地位
  const identity = ref([
    {label: "全部诉讼地位",value: ""},
    {label: "原告",value:"2"},
    {label: "被告",value:"1"},
    {label: "第三人/其他",value:"3"},
  ])


  // 图谱和次级债务人叠柱图使用的系列颜色
  const defaultColors = [
    '#4458FE','#3D4FE5','#3646CB','#303EB2','#293598',
    '#694EF1','#5F46D9','#543EC1','#4A37A9','#3F2F91',
    '#029FE9','#028FD2','#027FBA','#016FA3','#015F8C',
    '#00897B','#007B6F','#006E62','#006056','#00524A'
  ]

  // 债务人名单下载模板地址
  const debtorTemplateUrl = "https://files.bczcc.com/%E5%80%BA%E5%8A%A1%E4%BA%BA%E6%95%B0%E6%8D%AE%E4%B8%8A%E4%BC%A0%E6%A8%A1%E6%9D%BF.xlsx?attname=债务人数据上传模板.xlsx"

  // 地区列表 省市
  const areaList = ref([])

  const getAllPlace = async () => {
    // id name cityVos
    const res = await getAllPlaceApi()
    areaList.value = res.content
  }

  return { auditStatus, clueStatus, amountLevel, caseIdentity, areaList, getAllPlace, positionStatus, caseType, defaultColors, debtorTemplateUrl, caseProgress, WsType, identity }
})
/** 在 setup 外使用 */
export function useUseDictHook() {
  return useDict(store)
}
